<?php
namespace Administrator\Form\Filter;

use Zend\InputFilter\InputFilter;
use Administrator\Form\LoginForm;

class LoginFilter extends InputFilter {

    public function loginformfilter(){
        
        $isEmpty = \Zend\Validator\NotEmpty::IS_EMPTY;
        $invalidEmail = \Zend\Validator\EmailAddress::INVALID_HOSTNAME;
        
        $this->add(array(
            'name' => 'email',
            'required' => true,
            'filters' => array(
                array('name' => 'StripTags'),
                array('name' => 'StringTrim'),
            ),
            'validators' => array(
                array(
                    'name' => 'NotEmpty',
                    'options' => array(
                        'messages' => array(
                            $isEmpty => 'Email không được để trống.'
                        )
                    ),
                    'break_chain_on_failure' => true
                ),
                array(
                    'name' => 'EmailAddress',
                    'options' => array(
                        'messages' => array(
                            $invalidEmail => 'Kiểm tra lại email.'
                        )
                    )
                )
            ),
        ));
        
        $this->add(array(
            'name' => 'password',
            'required' => true,
            'filters' => array(
                array('name' => 'StripTags'),
                array('name' => 'StringTrim'),
            ),
            'validators' => array(
                array(
                    'name' => 'NotEmpty',
                    'options' => array(
                        'messages' => array(
                            $isEmpty => 'Mật khẩu không để trống.'
                        )
                    )
                )
            )
        ));

    }
    
    /* public function minifyfilter() {
    	$selectfile = new LoginForm();
    	$getfilefilter = $selectfile->getfile();
    	$arrselct = array();
    	foreach ($getfilefilter as $key => $val){
    		$arrselct[]=$key;
    	}

    	$this->add(array(
    			'name' => 'jsandcssfile',
    			'required' => true,
    			'filters' => array(
    					array('name' => 'StripTags'),
    					array('name' => 'StringTrim'),
    			),
    			'validators' => array(
    					array(
    							'name' => 'NotEmpty',
    							'options' => array(
    									'type' => array(
    											\Zend\Validator\NotEmpty::NULL,
    									),
    							)
    					),
    					array(
    							'name'   => 'InArray',
    							'options' => array(
    									'haystack' => $arrselct,
    									'strict' => \Zend\Validator\InArray::COMPARE_NOT_STRICT_AND_PREVENT_STR_TO_INT_VULNERABILITY,
    									'messages' => array(
    											\Zend\Validator\InArray::NOT_IN_ARRAY => 'Vui lòng chọn file.',
    									),
    							),
    					),
    			)
    	));
    } */
    
    public function userformfilter($dbAdapter){
    
    	$isEmpty = \Zend\Validator\NotEmpty::IS_EMPTY;
    	$invalidEmail = \Zend\Validator\EmailAddress::INVALID_HOSTNAME;    
    
    	$this->add(array(
    			'name' => 'email_user',
    			'required' => true,
    			'filters' => array(
    					array('name' => 'StripTags'),
    					array('name' => 'StringTrim'),
    			),
    			'validators' => array(
    					array(
    							'name' => 'NotEmpty',
    							'options' => array(
    									'messages' => array(
    											$isEmpty => 'Email không được để trống.'
    									)
    							),
    							'break_chain_on_failure' => true
    					),
    					array(
    							'name' => 'EmailAddress',
    							'options' => array(
    									'messages' => array(
    											$invalidEmail => 'Kiểm tra lại email.'
    									)
    							)
    					)
    			),
    	));
    
    	$selectsp = new LoginForm();
    	$selectsp->userform(null,$dbAdapter);
    	$valselect = $selectsp->getOptionsForSelectrole();
    	$arrselct = array();
    	foreach ($valselect as $key => $val){
    		$arrselct[]=$key;
    	}
    	$this->add(array(
    			'name' => 'vaitro_user',
    			'required' => true,
    			'filters' => array(
    					array('name' => 'StripTags'),
    					array('name' => 'StringTrim'),
    			),
    			'validators' => array(
    					array(
    							'name' => 'NotEmpty',
    							'options' => array(
    									'type' => array(
    											\Zend\Validator\NotEmpty::NULL,
    									),
    							)
    					),
    					array(
    							'name'   => 'InArray',
    							'options' => array(
    									'haystack' => $arrselct,
    									'strict' => \Zend\Validator\InArray::COMPARE_NOT_STRICT_AND_PREVENT_STR_TO_INT_VULNERABILITY,
    									'messages' => array(
    											\Zend\Validator\InArray::NOT_IN_ARRAY => 'Vui lòng chọn vai trò.',
    									),
    							),
    					),
    			)
    	));
    }
}